<template>
  <div class="card-page">
    <tool-bar nav="" :title="action_name + 'jenkinsLog'">
      <el-button size="small" @click="$router.push('/dev/jenkins-log/add')" v-if="$props.action=='edit'">新建</el-button>
      <el-button size="small" @click="save_click" type="primary"> 保存</el-button>
    </tool-bar>
    <el-row :gutter="12" type="flex">
      <el-col :span="12">
        <el-card shadow="always">

            <template #header> <span>基本信息</span> </template>
          <kv label="status">
            <selector v-model="info.status" enum="JenkinsJobStatusEnum" chk="*"/>
          </kv>
          <kv label="stages">
            <el-input v-model="info.stages" />
          </kv>
          <kv label="gitData">
            <el-input v-model="info.gitData" />
          </kv>
          <kv label="gitBuildInfo">
            <el-input v-model="info.gitBuildInfo" />
          </kv>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card shadow="always">

            <template #header> <span>扩展信息</span> </template>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
/**
 * Created by CodeGenerator  at 2022-02-20 12:46:33
 */




//定义 vue2的this,当前组件
const $self = getCurrentInstance();

//定义 $attrs
const $attrs = useAttrs();



//定义data
const $data = reactive({
    JenkinsJobStatusEnum: jv.enum.JenkinsJobStatusEnum.getData(),
    info: {
        stages: [],
        gitData: {},
        gitBuildInfo: {},
        createBy: {},
    }, //子对象需要声明。
});
const info = $computed(()=> $data.info );

const $props = defineProps({
    action: { type: String } ,
    id : { type: String }
});

const list = ref();

//定义事件
const $emit = defineEmits(["update:modelValue","loaded"]);

const action = $computed( function() {
    return $props.id ? "edit" : "add";
});
const action_name = $computed( function() {
    return {add: "添加", edit: "修改"}[$props.action]
});

const loadData = async function() {
    if (!$props.id) return;
    var res = await jv.$http.post("/dev/jenkins-log/detail/" + $props.id)
    $data.info = res.data.data;
};
const save_click = async function() {
//校验
    if (jv.chk_main($data) == false) {
        return;
    }
    var res =await jv.$http.post("/dev/jenkins-log/save", $data.info)
//[axios拦截器中已处理了异常]。
    jv.info(action_name + " 成功");
    if ($props.action == "add") {
        var id = res.data.data
        jv.setLastRowId("/dev/jenkins-log/list", "list", id);
        jv.$router.push("/dev/jenkins-log/edit/" + id)
    } else if ($props.action == "edit") {
        jv.$router.push("/dev/jenkins-log/list")
    }
};

onMounted( function() {
    loadData();
} )



</script>
